package com.zzb.myshowme.view.activity;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.zzb.myshowme.R;
import com.zzb.myshowme.view.fragment.ChangePhoneFragment;
import com.zzb.myshowme.view.fragment.SecondPasswordFragment;

//改变用户的绑定手机或密码
public class ChangeInformationActivity extends BaseActivity {

    FragmentManager manager;
    public String phone;
    ChangePhoneFragment cpf;
    SecondPasswordFragment spf;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_change_information);
        Intent intent = getIntent();
        String type = intent.getStringExtra("type");
        Log.d("test", "type = " + type);
        if(type.equals("phone")){
            gotoChangePhone();
        }else if(type.equals("password")){
            gotoGetPassword();
        }
    }

    /**
     * 跳转到修改手机号界面
    */
    public void gotoChangePhone() {
        if (manager == null) {
            manager = this.getFragmentManager();
        }
        FragmentTransaction transaction = manager.beginTransaction();
        cpf = (ChangePhoneFragment) manager.findFragmentByTag("changephone");
        if (cpf == null) {
            cpf = new ChangePhoneFragment();
        }
        transaction.replace(R.id.frameLayout, cpf, "changephone");
        transaction.addToBackStack(null);
        transaction.commit();
    }


    /**
     * 跳转到修改密码界面
     */
    public void gotoGetPassword() {
        if (manager == null) {
            manager = this.getFragmentManager();
        }
        FragmentTransaction transaction = manager.beginTransaction();
        spf = (SecondPasswordFragment) manager.findFragmentByTag("secondpassword");
        if (spf == null) {
            spf = new SecondPasswordFragment();

        }
        transaction.replace(R.id.frameLayout, spf, "secondpassword");
        transaction.addToBackStack(null);
        transaction.commit();
    }
}
